home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / utility3 / makemdi2.zip / APP.C next >
C/C++ Source or Header  |  1992-11-25  |  4KB  |  166 lines

  1. #define _APP_C
  2. //----------------------------------------------------------------- 
  3. // APP.C - <description> 
  4. // 
  5. // MAKEMDI adaptation of Windows 3.1 SDK MAKEAPP system. 
  6. // 
  7. // MDI application design based on Chapter 7 of     
  8. // "Windows 3: A Developer's Guide" by Jeffrey Richter. 
  9. // 
  10. // Adaptation developed with permission of the author by  
  11. // John F. Holliday, Technisoft Corporation 
  12. // Telephone: (515) 472-9803, CompuServe: 71271,634 
  13. //
  14. // [DMM]    25-Nov-1992: Fixed crashing on exit
  15. //            Also tabified file to tabsize of 4
  16. //
  17. //            David M. Miller, Business Visions, Inc.
  18. //            Telephone: (212) 747-6118
  19. //            CompuServe: 72676,327
  20. //            internet: dmiller@hera.sbi.com
  21. //----------------------------------------------------------------- 
  22. #include "makemdi.h"
  23.  
  24.  
  25. APP                g_app;
  26.  
  27.  
  28. int PASCAL        WinMain(HINSTANCE hinst, HINSTANCE hinstPrev,
  29.                                         LPSTR lpszCmdLine, int cmdShow)
  30. {
  31.     int                exitCode = 1;
  32.  
  33.     // Initialize the APP structure 
  34.     // 
  35.     g_app.hinst = hinst;
  36.     g_app.hinstPrev = hinstPrev;
  37.     g_app.lpszCmdLine = lpszCmdLine;
  38.     g_app.cmdShow = cmdShow;
  39.     g_app.hWndFrame = NULL;
  40.  
  41.     // Initialize, run, and terminate the application 
  42.     // 
  43.  
  44.     if (App_Initialize(&g_app)) {
  45.         exitCode = App_Main(&g_app);
  46.         App_Terminate(&g_app, FALSE);
  47.     }
  48.  
  49.     return exitCode;
  50. }
  51.  
  52.  
  53.  
  54.  
  55. int                App_Main(APP * papp)
  56. {
  57.     while (TRUE) {
  58.         MSG                msg;
  59.  
  60.         // If a message exists in the queue, translate and dispatch it. 
  61.         // 
  62.         if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
  63.             // If it's time to quit, return exit code 
  64.             // 
  65.             if (msg.message == WM_QUIT)
  66.                 return (int) msg.wParam;
  67.  
  68.             TranslateMessage(&msg);
  69.             DispatchMessage(&msg);
  70.         }
  71.         else {
  72.             // No messages: do idle processing. 
  73.             // If the app is idle, just wait for another message. 
  74.             // 
  75.             if (App_Idle(papp))
  76.                 WaitMessage();
  77.         }
  78.     }
  79. }
  80.  
  81.  
  82.  
  83.  
  84. BOOL            App_Initialize(APP * papp)
  85. {
  86.     BOOL            bResult = FALSE;
  87.  
  88.     if (papp->hinstPrev) {
  89.         // Only one instance allowed. 
  90.  
  91.         HWND            hWnd, hWnd1;
  92.  
  93.         hWnd = FindWindow(CLASS_FRAME, NULL);
  94.  
  95.         if (IsWindow(hWnd)) {
  96.             hWnd1 = GetLastActivePopup(hWnd);
  97.  
  98.             if (IsWindow(hWnd1))
  99.                 hWnd = hWnd1;
  100.  
  101.             BringWindowToTop(hWnd);
  102.  
  103.             if (IsIconic(hWnd))
  104.                 ShowWindow(hWnd, SW_RESTORE);
  105.  
  106.             SetFocus(hWnd);
  107.         }
  108.  
  109.         return FALSE;
  110.     }
  111.  
  112.     // Initialize the frame class and all MDI child window classes 
  113.     // before creating and showing the top level frame instance. 
  114.  
  115.     if (Frame_Initialize(papp) && Client_Initialize(papp)) {
  116.         LoadString(papp->hinst, IDS_APPNAME, papp->szName, sizeof(papp->szName));
  117.         LoadString(papp->hinst, IDS_APPCAPTION, papp->szBuf, sizeof(papp->szBuf));
  118.  
  119.         papp->hWndFrame = Frame_CreateWindow(
  120.                                                 papp->szBuf,
  121.                                                 CW_USEDEFAULT, CW_USEDEFAULT,
  122.                                                 CW_USEDEFAULT, CW_USEDEFAULT,
  123.                                                 papp->hinst);
  124.  
  125.         if (papp->hWndFrame != NULL) {
  126.             bResult = TRUE;
  127.             ShowWindow(papp->hWndFrame, papp->cmdShow);
  128.         }
  129.     }
  130.  
  131.     return bResult;
  132. }
  133.  
  134.  
  135.  
  136.  
  137. void            App_Terminate(APP * papp, BOOL fEndSession)
  138. //----------------------------------------------------------------- 
  139. // Flush any caches and buffers to disk, if necessary. 
  140. // 
  141. // If fEndSession is TRUE, it is not necessary to 
  142. // destroy windows, GDI objects, or free memory. 
  143. //----------------------------------------------------------------- 
  144. {
  145.     if (!fEndSession) {
  146.         Client_Terminate(papp);
  147.         Frame_Terminate(papp);
  148.     }
  149. }
  150.  
  151.  
  152.  
  153.  
  154. BOOL            App_Idle(APP * papp)
  155. //----------------------------------------------------------------- 
  156. // Return TRUE if the app is idle, FALSE if there is more work to do. 
  157. // 
  158. // NOTE: To implement background processing, perform the next chunk 
  159. // of the pending background process now, then return FALSE if there 
  160. // is more background processing to be done.  Return TRUE only if 
  161. // all background processing is completed. 
  162. //----------------------------------------------------------------- 
  163. {
  164.     return TRUE;
  165. }
  166.